package com.yuanfeng.job.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.job.entity.JobDayOrderStaticsEntity;
import com.yuanfeng.job.mapper.JobDayOrderStaticsMapper;
import com.yuanfeng.job.service.JobDayOrderStaticsService;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *
 */
@Service
public class JobDayOrderStaticsServiceImpl extends ServiceImpl<JobDayOrderStaticsMapper, JobDayOrderStaticsEntity>
    implements JobDayOrderStaticsService {

    @Override
    public Map<String, Double> countStatics(Date start, Date end) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //已完成订单
        Map<String,String> completeMap = new HashMap<>();
        completeMap.put("orderFinishedStartTime",sdf.format(start));
        completeMap.put("orderFinishedEndTime",sdf.format(end));
        completeMap.put("orderStatus","6");
        Map<String, String> completeOrder = this.baseMapper.countOrderBase(completeMap);

        //已取消订单
        Map<String,String> cancelMap = new HashMap<>();
        cancelMap.put("orderCancelStartDate",sdf.format(start));
        cancelMap.put("orderCancelEndDate",sdf.format(end));
        cancelMap.put("orderStatus","7");
        Map<String, String> cancelOrder = this.baseMapper.countOrderBase(cancelMap);

        //总订单
        Map<String,String> totalMap = new HashMap<>();
        totalMap.put("orderCreateStartTime",sdf.format(start));
        totalMap.put("orderCreateEndTime",sdf.format(end));
        Map<String, String> totalOrder = this.baseMapper.countOrderBase(totalMap);

        //完成的退款
        Map<String,String> returnMap = new HashMap<>();
        returnMap.put("orderReturnStartTime",sdf.format(start));
        returnMap.put("orderReturnEndTime",sdf.format(end));
        returnMap.put("returnState","5");
        Map<String, String> returnOrder = this.baseMapper.countAfterSaleOrder(returnMap);

        //插入每日统计表
        Map<String,Double> paraMap = new HashMap<>();
        paraMap.put("totalRefundFee", Double.parseDouble(returnOrder.get("returnCash").toString()));
        paraMap.put("totalRefundTrade",Double.parseDouble(returnOrder.get("completeTrade").toString()));
        paraMap.put("totalPaymentAmount",Double.parseDouble(totalOrder.get("orderPaymentAmount").toString()));
        paraMap.put("totalOrderTrade",Double.parseDouble(totalOrder.get("completeTrade").toString()));
        paraMap.put("completeTrade",Double.parseDouble(completeOrder.get("completeTrade").toString()));
        paraMap.put("completeFee",Double.parseDouble(completeOrder.get("orderPaymentAmount").toString()));
        paraMap.put("cancleTrade",Double.parseDouble(cancelOrder.get("completeTrade").toString()));
        paraMap.put("cancleFee",Double.parseDouble(cancelOrder.get("orderPaymentAmount").toString()));

        return paraMap;
    }
}




